class Solution376 {
    public int wiggleMaxLength(int[] nums) {
        if (nums.length <= 1) return nums.length;
        int n = nums.length;
        int len = 1;
        int right = 1;
        int prev = nums[0];
        while (right < n) {
            if (nums[right] > prev) {
                while (right < n && nums[right] >= prev) {
                    prev = nums[right];
                    right++;
                }
                len++;
            } else if (nums[right] < prev) {
                while (right < n && nums[right] <= prev) {
                    prev = nums[right];
                    right++;
                }
                len++;
            }else{
                right ++ ; 
            }
        }
        return len ; 

    }
}
